<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
$(function(){
	//弹出框设置
	$("#dialogDiv").dialog({
		title:"呈送单位维护",//标题
		width: 800,//宽度
	    height: 200,//高度
	    closed: true,//初始关闭
	    cache: false,//缓存
	    modal: true,
	    onClose: function() {
			 $("#dialogIframe").attr("src","");
			} 
	});
	
	
	//新增按钮绑定点击事件
	$("#addButton").click(function(){
		$("#dialogIframe").attr("src","<c:url value='/docTargetUnitManager/add' />");
		$('#dialogDiv').dialog('open').window('center');
	});
	
	//编辑按钮绑定点击事件
	$("#updateButton").click(function(){
		if($("input[name='targetId']:checked").size()==1){
			$("#dialogIframe").attr("src","<c:url value='/docTargetUnitManager/edit' />?id="+$("input[name='targetId']:checked").val());
			$('#dialogDiv').dialog('open').window('center');
		}else{
			$.messager.alert('提示','请选择一条数据再编辑');
		}
	});
	
	//删除按钮绑定点击事件
	$("#deleteButton").click(function(){
		if($("input[name='targetId']:checked").size()==1){
			$.messager.confirm('提示', '确定要删除数据吗?', function(r){
				if (r){
					$.ajax({
						   type: "POST",
						   url: "<c:url value='/docTargetUnitManager/delete' />",
						   data: "id="+$("input[name='targetId']:checked").val(),
						   success: function(msg){
							   if(msg.state=="200"){
								   $.messager.alert('提示','数据删除成功');
								   $('#doctargetTable').datagrid({ queryParams:getParams()});
							   }else{
								   $.messager.alert('提示',"数据删除失败");
							   }
						   }
						});
				}
			});
		}else{
			$.messager.alert('提示','请选择一条数据再删除');
		}
	});
	//表格加载
	$('#doctargetTable').datagrid({
	    url:'<c:url value="/docTargetUnitManager/listData" />',
	    toolbar:'#doctargetToolbar',//表头工具栏
	    pagination:true,//显示分页  
	    pagePosition:'bottom',//分页栏出现位置
	    pageNumber:1,//初始页码
	    pageSize:10,//初始每页显示记录数量
	    singleSelect:true,
	    columns:[[
			{field:'id',title:'',formatter: function(value,row,index){
				return '<input name="targetId" type="radio" value="'+value+'" />';
			},width:25},
			{field:'targetUnitName',title:'呈送单位统称'},
			{field:'targetType',title:'呈送类型',formatter: function(value,row,index){
				if(value=='MT'){
					return '主送';
					}		
				if(value=='ST'){
					return '分送';
					}		
				
				if(value=='CT'){
					return '抄送';
					}		
				
				if(value=='RT'){
					return '抄报';
				}		
			}}
//			{field:'topOrgCode',title:'单位code'},
//			{field:'topOrgName',title:'单位名称'},
//			{field:'delFlag',title:'删除标识'},
//			{field:'remark1',title:'保留字段1'},
//			{field:'remark2',title:'保留字段2'}
	    ]]
	});
});



//查询条件生成方法
function getParams(){
	var jsonObj=new Object();
	return jsonObj;
}
//关闭弹出框
function closeDialog(){
	$('#doctargetTable').datagrid({ queryParams:getParams()});
	$('#dialogDiv').dialog('close');
}
